package miage.rest.validation;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 *
 * @author marya
 */
public class DateValidator extends AbstractValidator {
	private final String pattern;
	private final String patternHint;

	public DateValidator(String pattern, String patternHint) {
		this.pattern = pattern;
		this.patternHint = patternHint;
	}

	public boolean isValid(String value) {
		Date date = null;
		DateFormat df = new SimpleDateFormat(pattern);
		try {
			date = df.parse(value);
		} catch(Exception e) {
			this.addMessage(value + " doit être au format " + patternHint);
		}
		return date != null;
	}

}
